package br.com.salao.model;

import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;

import javax.persistence.EntityManager;

import br.com.salao.bean.Login;
import br.com.salao.dao.LoginDao;
import br.com.salao.dao.LoginDaoImpl;
import br.com.salao.security.Criptografia;
import br.com.salao.util.JpaUtil;


public class LoginModel {

	private EntityManager em;

	public LoginModel(){
		em = JpaUtil.getEntityManager();	
	}

	public String criptografarSenha(String senha) throws NoSuchAlgorithmException, UnsupportedEncodingException{

		String senhaCriptografada = "";

		Criptografia criptografia = new Criptografia();
		senhaCriptografada = criptografia.gerarSenhaCriptografada(senha);

		return senhaCriptografada;
	}

	public Login buscarLogin(String login){
		LoginDao dao = new LoginDaoImpl(em);
		return dao.buscarLogin(login);
	}

	public Login buscar(int id){
		LoginDaoImpl dao = new LoginDaoImpl(em);
		return dao.buscar(id);
	}
	
	public Login inserir(Login login){
		LoginDaoImpl dao = new LoginDaoImpl(em);
		return dao.inserir(login);
	}
}
